package common

import (
	"math/rand"
	"time"
)

// GetRandomString 生成随机字符串
func GetRandomString(n int) string {
	const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	b := make([]byte, n)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for i := range b {
		b[i] = letterBytes[r.Int63()%int64(len(letterBytes))]
	}
	return string(b)
}

// RandIntValueInSlice 从切片中随机选择
func RandIntValueInSlice(s []int) int {
	if len(s) <= 0 {
		return 0
	}
	t := rand.NewSource(time.Now().Unix())
	r := rand.New(t)
	v := r.Intn(len(s))
	return s[v]
}
